package com.scpii.universal.hibernate.dao.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Repository;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.hibernate.dao.AttributeValueDao;
import com.scpii.universal.hibernate.entity.AttributeValueTab;

/**
 * universalWeb
 * @author liuhj
 * 2012-7-5下午05:16:31
 */
@Repository
public class AttributeValueDaoImpl extends BaseDaoImpl<AttributeValueTab, Integer> implements AttributeValueDao {

	@Override
	public void delete(String ids) {
		String hql = "update AttributeValueTab a set a.intDeleteSign=?,a.datMudifyDate=? "
			+ "where a.intAttriId in" + ids;
		getHibernateTemplate().getSessionFactory().getCurrentSession()
			.createQuery(hql).setParameter(0,
					GenericConstants.DELETE_SIGN_DELETED).setParameter(
					1,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
							.format(new Date())).executeUpdate();
	}

	@Override
	public void deleteByAttrId(int attrId) {
		String hql = "update AttributeValueTab a set a.intDeleteSign=?,a.datMudifyDate=? "
			+ "where a.intAttriId=?";
		getHibernateTemplate().getSessionFactory().getCurrentSession()
			.createQuery(hql).setParameter(0,
					GenericConstants.DELETE_SIGN_DELETED).setParameter(
					1,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
							.format(new Date())).setParameter(2, attrId).executeUpdate();
	}

	@Override
	public void deleteByContId(int contentId) {
		String hql = "delete AttributeValueTab a where a.intContentId=?";
		getHibernateTemplate().getSessionFactory().getCurrentSession()
			.createQuery(hql).setParameter(0,contentId).executeUpdate();
	}
	
}
